<?php

namespace app\health\model;

use think\Model;

/**
 * 站点轮播图模型
 */
class HealthWebsiteBanner extends Model
{
    // 表名
    protected $name = 'health_website_banner';

    public const POSITION_MAP = [
        1 => '首页',
        2 => '商品'
    ];

    public const TYPE_MAP = [
        0 => '内部页面',
        1 => '其他小程序',
        2 => '无跳转'
    ];

    protected $append = ['type_text', 'status_text'];

    /**
     * 获取跳转类型描述
     * @param [type] $val
     * @param [type] $data
     * @Author 张旭鹏
     * @DateTime 2023-07-13
     */
    public function getTypeTextAttr($val, $data)
    {
        $type = $data['type'] ?? '-1';

        return self::TYPE_MAP[$type] ?? '-';
    }

    /**
     * 状态描述
     * @param [type] $val
     * @param [type] $data
     * @Author 张旭鹏
     * @DateTime 2023-07-13
     */
    public function getStatusTextAttr($val, $data)
    {
        $map = [1 => '启用中', 0 => '禁用中'];
        return $map[$data['status']];
    }

    public function getParamsAttr($val)
    {
        return json_decode($val, true);
    }

    public function setParamsAttr($val)
    {
        return json_encode($val, JSON_UNESCAPED_UNICODE);
    }
}
